#ifndef __ZW101_H
#define __ZW101_H

#ifdef APM32E10X_HD
	#include "apm32e10x_gpio.h"     
	#include "apm32e10x_rcm.h"
	#include "apm32e10x_eint.h"
	
#elif defined AT32F403AVGT7
	#include "at32f403a_407_gpio.h"
	#include "at32f403a_407_crm.h"
	#include "at32f403a_407_exint.h"
	
#else
	#include "apm32f10x_gpio.h"     
	#include "apm32f10x_rcm.h"
	#include "apm32f10x_eint.h"
	
#endif

#include "BoardData.h"
#include "tools.h"
#include "uart.h"  
#include <stdio.h>


////   指纹识别   ////
#ifdef SQDri_EVSEB_11KW
	//引脚块1 = 活体检测引脚 = PC9 
	#define ZW101_RCM               RCM_APB2_PERIPH_GPIOC                         
	#define ZW101_PinPort           GPIOC    
	#define ZW_TouchOut_PinId       GPIO_PIN_9  

	#if finger_sensor_type == Finger_HLK_ZW101_EINT
	//外部中断
	#define ZW101_RCM_EINT        RCM_APB2_PERIPH_AFIO
	#define ZW101_EintPort        GPIO_PORT_SOURCE_C
	#define ZW101_EintPin         GPIO_PIN_SOURCE_9
	#define ZW101_EintLine        EINT_LINE_9
	#define ZW101_Eint_IRQn       EINT9_5_IRQn
	#define ZW101_Eint_Fun        EINT9_5_IRQHandler
	#endif

#else

	//引脚块1 = 活体检测引脚 = PC9 
	#define ZW101_RCM               RCM_APB2_PERIPH_GPIOC                         
	#define ZW101_PinPort           GPIOC    
	#define ZW_TouchOut_PinId       GPIO_PIN_9  

	#if finger_sensor_type == Finger_HLK_ZW101_EINT
	//外部中断
	#define ZW101_RCM_EINT        RCM_APB2_PERIPH_AFIO
	#define ZW101_EintPort        GPIO_PORT_SOURCE_C
	#define ZW101_EintPin         GPIO_PIN_SOURCE_9
	#define ZW101_EintLine        EINT_LINE_9
	#define ZW101_Eint_IRQn       EINT9_5_IRQn
	#define ZW101_Eint_Fun        EINT9_5_IRQHandler
	#endif
	
#endif // define SQDri_EVSEB_11KW


/////////// 命令相关 ///////
// 包头
#define Finger_Header_H         0xEF
#define Finger_Header_L         0x01
// 设备地址
#define ZW_Device_Addr0         0xff
#define ZW_Device_Addr1         0xff
#define ZW_Device_Addr2         0xff
#define ZW_Device_Addr3         0xff
// 包标志
#define  Flag_CMD               0x01
#define  Flag_Data              0x02
#define  Flag_DataEnd           0x08
#define  Flag_Reply             0x07

////////// 指令 ////////////
// 通用指令
#define  PS_GetImage            0x01   
#define  PS_GenChar             0x02 
#define  PS_Match               0x03 
#define  PS_Search              0x04 
#define  PS_RegModel            0x05 
#define  PS_StoreChar           0x06 
#define  PS_LoadChar            0x07 
#define  PS_UpChar              0x08 
#define  PS_DownChar            0x09 
#define  PS_DeletChar           0x0c 
#define  PS_Empty               0x0d
#define  PS_WriteReg            0x0e 
// 读取模组基本信息：
#define  PS_ReadSysPara         0x0f
#define  PS_ReadINFpage         0x16
#define  PS_ValidTempleteNum    0x1d
#define  PS_ReadIndexTable      0x1f 
#define  PS_GetEnrollImage      0x29 
#define  PS_ReadAddPara         0x62 
#define  PS_Sleep               0x33
#define  PS_Cancel              0x30 
#define  PS_AutoEnroll          0x31
#define  PS_AutoIdentify        0x32
#define  PS_UpImage_4Bit        0x0a
#define  PS_UpImage_8Bit        0x6a
#define  PS_DownImage_4Bit      0x0b 
#define  PS_DownImage_8Bit      0x6b 
#define  PS_GetChipSN           0x34
#define  PS_HandShake           0x35
#define  PS_CheckSensor         0x36 
#define  PS_RestSetting         0x3B

// 定制类指令集
#define  PS_SetPwd              0x12 
#define  PS_VfyPwd              0x13 
#define  PS_SetChipAddr         0x15 
#define  PS_WriteNotepad        0x18 
#define  PS_ReadNotepad         0x19 
#define  PS_BlnAmSw             0x60 
// 呼吸灯指令
#define  PS_ControlBLN          0x3C 
// 获取图像信息
#define  PS_GetImageInfo        0x3D 
// 搜索当前指纹指令
#define  PS_SearchNow           0x3E


///// 函数声明 //////
void zw101_pin_init(void);
#if finger_sensor_type == Finger_HLK_ZW101_EINT
void zw101_EINT_start(void);
#endif
uint8_t zw101_TouchOut_get_level(void); 
void finger_sendCmd(uint8_t cmdStr);

#endif


